#!/bin/sh

prefix=@prefix@

echo building PowerDNS chroot in $prefix
echo -n "Copying libraries: "
cp $(./finddeps ahudns resolver dynloader /bin/sh) $prefix/lib
echo done
echo -n "Copying in /bin/sh: "
cp /bin/sh $prefix/bin
echo done

preprefix=$(echo $prefix | sed s/$(basename $prefix)//)

echo -n "Making tmp and pre-prefix in root: "
mkdir -p $prefix/tmp $prefix/$preprefix
echo "done"
echo -n "Creating $prefix in $prefix: "
cd $prefix/$preprefix
ln -s .. $(basename $prefix)
cd -
echo done
echo -n "Creating launch script: "
echo \#\!/bin/sh > $prefix/launch
echo cd $prefix >> $prefix/launch 
echo export ORACLE_HOME=$prefix/oracle >> $prefix/launch
echo chroot . ./bin/ahudns >> $prefix/launch
chmod +x $prefix/launch
echo done

